library(sf)
Linking to GEOS 3.6.1, GDAL 2.2.3, proj.4 4.9.3
library(tidyverse)
[37m-- [1mAttaching packages[22m --------------------------------------- tidyverse 1.2.1 --[39m
[37m[32mv[37m [34mggplot2[37m 3.0.0 [32mv[37m [34mpurrr [37m 0.2.5
[32mv[37m [34mtibble [37m 1.4.2 [32mv[37m [34mdplyr [37m 0.7.6
[32mv[37m [34mtidyr [37m 0.8.1 [32mv[37m [34mstringr[37m 1.3.1
[32mv[37m [34mreadr [37m 1.1.1 [32mv[37m [34mforcats[37m 0.3.0[39m
[37m-- [1mConflicts[22m ------------------------------------------ tidyverse_conflicts() --
[31mx[37m [34mdplyr[37m::[32mfilter()[37m masks [34mstats[37m::filter()
[31mx[37m [34mdplyr[37m::[32mlag()[37m masks [34mstats[37m::lag()[39m
library(tigris)
To enable
caching of data, set `options(tigris_use_cache = TRUE)` in your R script or .Rprofile.
Attaching package: 㤼㸱tigris㤼㸲
The following object is masked from 㤼㸱package:graphics㤼㸲:
plot
Get shapefile for US
ny_area <- states(class = "sf", year = 2000)
|
| | 0%
|
| | 1%
|
|= | 1%
|
|== | 2%
|
|=== | 3%
|
|=== | 4%
|
|==== | 4%
|
|==== | 5%
|
|===== | 5%
|
|===== | 6%
|
|====== | 6%
|
|====== | 7%
|
|======= | 7%
|
|======= | 8%
|
|======== | 8%
|
|======== | 9%
|
|========= | 9%
|
|========= | 10%
|
|========== | 10%
|
|========== | 11%
|
|=========== | 11%
|
|=========== | 12%
|
|============ | 12%
|
|============ | 13%
|
|============= | 13%
|
|============= | 14%
|
|============== | 14%
|
|============== | 15%
|
|=============== | 15%
|
|=============== | 16%
|
|================ | 16%
|
|================ | 17%
|
|================= | 17%
|
|================= | 18%
|
|================== | 18%
|
|================== | 19%
|
|=================== | 19%
|
|=================== | 20%
|
|==================== | 20%
|
|==================== | 21%
|
|===================== | 21%
|
|===================== | 22%
|
|====================== | 22%
|
|====================== | 23%
|
|======================= | 23%
|
|======================= | 24%
|
|======================== | 24%
|
|======================== | 25%
|
|========================= | 25%
|
|========================= | 26%
|
|========================== | 27%
|
|=========================== | 28%
|
|============================ | 29%
|
|============================= | 30%
|
|============================== | 31%
|
|=============================== | 32%
|
|================================ | 33%
|
|================================= | 34%
|
|================================== | 35%
|
|=================================== | 36%
|
|==================================== | 37%
|
|===================================== | 38%
|
|====================================== | 39%
|
|======================================= | 40%
|
|======================================== | 41%
|
|======================================== | 42%
|
|========================================= | 42%
|
|========================================= | 43%
|
|========================================== | 43%
|
|========================================== | 44%
|
|=========================================== | 44%
|
|=========================================== | 45%
|
|============================================ | 45%
|
|============================================ | 46%
|
|============================================= | 46%
|
|============================================= | 47%
|
|============================================== | 47%
|
|============================================== | 48%
|
|=============================================== | 48%
|
|=============================================== | 49%
|
|================================================ | 49%
|
|================================================ | 50%
|
|================================================= | 50%
|
|================================================= | 51%
|
|================================================== | 51%
|
|================================================== | 52%
|
|=================================================== | 52%
|
|=================================================== | 53%
|
|==================================================== | 53%
|
|==================================================== | 54%
|
|===================================================== | 54%
|
|===================================================== | 55%
|
|====================================================== | 55%
|
|====================================================== | 56%
|
|======================================================= | 56%
|
|======================================================= | 57%
|
|======================================================== | 57%
|
|======================================================== | 58%
|
|========================================================= | 58%
|
|========================================================= | 59%
|
|========================================================== | 59%
|
|========================================================== | 60%
|
|=========================================================== | 60%
|
|=========================================================== | 61%
|
|============================================================ | 61%
|
|============================================================ | 62%
|
|============================================================= | 62%
|
|============================================================= | 63%
|
|============================================================== | 64%
|
|=============================================================== | 65%
|
|================================================================ | 66%
|
|================================================================= | 67%
|
|================================================================== | 68%
|
|=================================================================== | 69%
|
|==================================================================== | 70%
|
|===================================================================== | 71%
|
|===================================================================== | 72%
|
|====================================================================== | 72%
|
|====================================================================== | 73%
|
|======================================================================= | 73%
|
|======================================================================= | 74%
|
|======================================================================== | 74%
|
|======================================================================== | 75%
|
|========================================================================= | 75%
|
|========================================================================= | 76%
|
|========================================================================== | 76%
|
|========================================================================== | 77%
|
|=========================================================================== | 77%
|
|=========================================================================== | 78%
|
|============================================================================ | 78%
|
|============================================================================ | 79%
|
|============================================================================= | 79%
|
|============================================================================= | 80%
|
|============================================================================== | 80%
|
|============================================================================== | 81%
|
|=============================================================================== | 81%
|
|=============================================================================== | 82%
|
|================================================================================ | 82%
|
|================================================================================ | 83%
|
|================================================================================= | 83%
|
|================================================================================= | 84%
|
|================================================================================== | 84%
|
|================================================================================== | 85%
|
|=================================================================================== | 85%
|
|=================================================================================== | 86%
|
|==================================================================================== | 86%
|
|==================================================================================== | 87%
|
|===================================================================================== | 87%
|
|===================================================================================== | 88%
|
|====================================================================================== | 88%
|
|====================================================================================== | 89%
|
|======================================================================================= | 89%
|
|======================================================================================= | 90%
|
|======================================================================================== | 90%
|
|======================================================================================== | 91%
|
|========================================================================================= | 91%
|
|========================================================================================= | 92%
|
|========================================================================================== | 92%
|
|========================================================================================== | 93%
|
|=========================================================================================== | 94%
|
|============================================================================================ | 95%
|
|============================================================================================= | 96%
|
|============================================================================================== | 97%
|
|=============================================================================================== | 98%
|
|================================================================================================ | 99%
|
|=================================================================================================| 100%
filter to NY and NJ
ny_area <- ny_area %>%
filter(NAME00 == "New York" |
NAME00 == "New Jersey" |
NAME00 == "Pennsylvania")
View sf.dataframe
as_tibble(ny_area)
tri_state <- ggplot() +
geom_sf(data = ny_area, aes(fill = NAME00)) +
coord_sf(xlim = c(-73, -75), ylim = c(40, 41.5))
tri_state
ggplot() +
geom_sf(data = ny_area, aes(fill = NAME00)) +
coord_sf(xlim = c(-73, -75), ylim = c(40, 41.5)) +
scale_fill_grey(start=1, end=0, name="% HCA")+
theme(axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_rect(fill="lightskyblue1"),
plot.background = element_rect(fill="lightskyblue1", color="black", size=1),
axis.line = element_blank(),
legend.key=element_rect(colour="black"),
legend.background=element_rect(colour="black"))
Thsi data approximates Ben’s examples
The counties New York City are:
manhattan <- tigris::tracts("NY", county = 061, year = 2000, class = "sf")
Using FIPS code '36' for state 'NY'
|
| | 0%
|
|= | 1%
|
|== | 2%
|
|=== | 3%
|
|=== | 4%
|
|==== | 4%
|
|===== | 5%
|
|===== | 6%
|
|====== | 6%
|
|======= | 7%
|
|======= | 8%
|
|======== | 8%
|
|========= | 9%
|
|========= | 10%
|
|========== | 10%
|
|========== | 11%
|
|=========== | 11%
|
|=========== | 12%
|
|============ | 12%
|
|============ | 13%
|
|============= | 13%
|
|============= | 14%
|
|============== | 14%
|
|============== | 15%
|
|=============== | 15%
|
|=============== | 16%
|
|================ | 16%
|
|================ | 17%
|
|================= | 17%
|
|================= | 18%
|
|================== | 18%
|
|================== | 19%
|
|=================== | 19%
|
|=================== | 20%
|
|==================== | 20%
|
|==================== | 21%
|
|===================== | 21%
|
|===================== | 22%
|
|====================== | 22%
|
|====================== | 23%
|
|======================= | 24%
|
|======================== | 24%
|
|======================== | 25%
|
|========================= | 26%
|
|========================== | 26%
|
|========================== | 27%
|
|=========================== | 28%
|
|============================ | 28%
|
|============================ | 29%
|
|============================= | 30%
|
|============================== | 31%
|
|=============================== | 32%
|
|================================ | 33%
|
|================================= | 34%
|
|================================== | 35%
|
|=================================== | 36%
|
|==================================== | 37%
|
|==================================== | 38%
|
|===================================== | 38%
|
|====================================== | 39%
|
|====================================== | 40%
|
|======================================= | 40%
|
|======================================== | 41%
|
|======================================== | 42%
|
|========================================= | 42%
|
|========================================= | 43%
|
|========================================== | 43%
|
|========================================== | 44%
|
|=========================================== | 44%
|
|=========================================== | 45%
|
|============================================ | 45%
|
|============================================ | 46%
|
|============================================= | 46%
|
|============================================= | 47%
|
|============================================== | 47%
|
|============================================== | 48%
|
|=============================================== | 48%
|
|=============================================== | 49%
|
|================================================ | 49%
|
|================================================ | 50%
|
|================================================= | 50%
|
|================================================= | 51%
|
|================================================== | 51%
|
|================================================== | 52%
|
|=================================================== | 52%
|
|=================================================== | 53%
|
|==================================================== | 53%
|
|==================================================== | 54%
|
|===================================================== | 54%
|
|===================================================== | 55%
|
|====================================================== | 55%
|
|====================================================== | 56%
|
|======================================================= | 56%
|
|======================================================= | 57%
|
|======================================================== | 58%
|
|========================================================= | 58%
|
|========================================================= | 59%
|
|========================================================== | 60%
|
|=========================================================== | 60%
|
|=========================================================== | 61%
|
|============================================================ | 62%
|
|============================================================= | 62%
|
|============================================================= | 63%
|
|============================================================== | 64%
|
|=============================================================== | 65%
|
|================================================================ | 66%
|
|================================================================= | 67%
|
|================================================================== | 68%
|
|=================================================================== | 69%
|
|=================================================================== | 70%
|
|==================================================================== | 70%
|
|===================================================================== | 71%
|
|===================================================================== | 72%
|
|====================================================================== | 72%
|
|======================================================================= | 73%
|
|======================================================================= | 74%
|
|======================================================================== | 74%
|
|========================================================================= | 75%
|
|========================================================================= | 76%
|
|========================================================================== | 76%
|
|========================================================================== | 77%
|
|=========================================================================== | 77%
|
|=========================================================================== | 78%
|
|============================================================================ | 78%
|
|============================================================================ | 79%
|
|============================================================================= | 79%
|
|============================================================================= | 80%
|
|============================================================================== | 80%
|
|============================================================================== | 81%
|
|=============================================================================== | 81%
|
|=============================================================================== | 82%
|
|================================================================================ | 82%
|
|================================================================================ | 83%
|
|================================================================================= | 83%
|
|================================================================================= | 84%
|
|================================================================================== | 84%
|
|================================================================================== | 85%
|
|=================================================================================== | 85%
|
|=================================================================================== | 86%
|
|==================================================================================== | 86%
|
|==================================================================================== | 87%
|
|===================================================================================== | 87%
|
|===================================================================================== | 88%
|
|====================================================================================== | 88%
|
|====================================================================================== | 89%
|
|======================================================================================= | 90%
|
|======================================================================================== | 90%
|
|======================================================================================== | 91%
|
|========================================================================================= | 92%
|
|========================================================================================== | 92%
|
|========================================================================================== | 93%
|
|=========================================================================================== | 94%
|
|============================================================================================ | 94%
|
|============================================================================================ | 95%
|
|============================================================================================= | 96%
|
|============================================================================================== | 97%
|
|=============================================================================================== | 98%
|
|================================================================================================ | 99%
|
|=================================================================================================| 100%
bronx <- tigris::tracts("NY", county = 005, year = 2000, class = "sf")
Using FIPS code '36' for state 'NY'
brooklyn <- tigris::tracts("NY", county = 047, year = 2000, class = "sf")
Using FIPS code '36' for state 'NY'
queens <- tigris::tracts("NY", county = 081, year = 2000, class = "sf")
Using FIPS code '36' for state 'NY'
staten <- tigris::tracts("NY", county = 085, year = 2000, class = "sf")
Using FIPS code '36' for state 'NY'
boroughs <- rbind(manhattan, bronx, brooklyn, queens, staten)
Plan to left_join on borroughts$CTIDFP00
as_tibble(boroughs)
Get Census Pop for Bororoughs, 2000
plan to lef_join on boro_pop$Geo_FIPS
boro_pop <- read_csv("data/boro_pop_2000.csv")
Parsed with column specification:
cols(
Geo_NAME = col_character(),
Geo_QName = col_character(),
Geo_FIPS = col_double(),
Geo_SUMLEV = col_integer(),
Geo_GEOCOMP = col_character(),
Geo_STATECE = col_integer(),
Geo_STATE = col_integer(),
Geo_COUNTY = col_character(),
Geo_COUNTYSC = col_integer(),
Geo_COUSUB = col_character(),
Geo_TRACT = col_character(),
SE_T001_001 = col_integer()
)
boro_pop <- boro_pop %>%
mutate(CTIDFP00 = as.character(Geo_FIPS)) %>%
rename(pop = SE_T001_001) %>%
select(CTIDFP00, pop)
boro_pop
left_join(boroughs, boro_pop, by = "CTIDFP00") -> boroughs
as_tibble(boroughs)
ggplot() +
geom_sf(data = boroughs, aes(fill = pop)) +
viridis::scale_fill_viridis() +
coord_sf(xlim = c(-73.6, -74.3), ylim = c(40.4, 41)) +
theme_bw()
first_pass <- ggplot() +
geom_sf(data = ny_area, aes(), color = "black", fill = "burlywood4") +
geom_sf(data = boroughs, aes(fill = pop)) +
viridis::scale_fill_viridis() +
coord_sf(xlim = c(-73.7, -74.3), ylim = c(40.45, 40.95))
first_pass
first_pass +
theme(axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.major = element_line(color = "transparent"),
panel.grid.minor = element_blank(),
panel.background = element_rect(fill="lightskyblue1"),
plot.background = element_rect(fill="lightskyblue1", color="black", size=1),
axis.line = element_blank(),
legend.key=element_rect(colour="black"),
legend.background=element_rect(colour="black"))
NA
Reverse viridis direction for greyscale.
ggplot() +
geom_sf(data = ny_area, aes(), color = "black", fill = "white") +
geom_sf(data = boroughs, aes(fill = pop)) +
viridis::scale_fill_viridis(direction = -1) +
coord_sf(xlim = c(-73.7, -74.3), ylim = c(40.45, 40.95)) +
theme(axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.major = element_line(color = "transparent"),
panel.grid.minor = element_blank(),
panel.background = element_rect(fill="lightskyblue1"),
plot.background = element_rect(fill="lightskyblue1", color="black", size=1),
axis.line = element_blank())
shapefile from: http://gis.ny.gov/gisdata/inventories/details.cfm?DSID=928
coast <- read_sf("data/hydrography_shp/AreaHydrography.shp")
as_tibble(coast)
Simple feature collection with 19974 features and 5 fields
geometry type: POLYGON
dimension: XY
bbox: xmin: 107250.5 ymin: 4481030 xmax: 770761.8 ymax: 4985490
epsg (SRID): 26918
proj4string: +proj=utm +zone=18 +datum=NAD83 +units=m +no_defs
resources may include:
coast1 <- st_set_crs(coast, st_crs(boroughs))
st_crs(coast)
st_crs(coast1)
st_crs(boroughs)
coast1 <- st_crop(coast1, st_bbox(boroughs))
foo <- st_intersection(boroughs, coast1)
ggplot() +
geom_sf(data = coast1)
st_bbox(boroughs)
st_crs(st_set_crs(coast, st_crs(boroughs)))
nycoast <- ggplot() +
geom_sf(data = coast)
nycoast
Borough choropleth + Sate Area boundaries + Hydrography
ggplot() +
geom_sf(data = ny_area, aes(), color = "black", fill = "white") +
geom_sf(data = borroughs, aes(fill = pop)) +
viridis::scale_fill_viridis(direction = -1) +
geom_sf(data = coast, color = "black", fill = "black") +
coord_sf(xlim = c(-73.7, -74.3), ylim = c(40.45, 40.95)) +
theme(axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.major = element_line(color = "transparent"),
panel.grid.minor = element_blank(),
panel.background = element_rect(fill="lightskyblue1"),
plot.background = element_rect(fill="lightskyblue1", color="black", size=1),
axis.line = element_blank())
removed state boundaries. population choropleth and hydrography remain.
ggplot() +
geom_sf(data = borroughs, aes(fill = pop)) +
viridis::scale_fill_viridis(direction = -1) +
geom_sf(data = coast, color = "black", fill = "black") +
coord_sf(xlim = c(-73.7, -74.3), ylim = c(40.45, 40.95)) +
theme(panel.background = element_rect(fill = "transparent"),
panel.grid.major = element_line(color = "transparent"),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank())